package com.ye.zcswzlms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ye.zcswzlms.entity.Lostproperty;
import com.ye.zcswzlms.entity.Users;
import com.ye.zcswzlms.mapper.LostpropertyMapper;
import com.ye.zcswzlms.service.ILostpropertyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 叶德辉
 * @since 2020-12-10
 */

@Service
public class LostpropertyServiceImpl extends ServiceImpl<LostpropertyMapper, Lostproperty> implements ILostpropertyService {
    @Autowired
    LostpropertyMapper lostpropertyMapper;
    @Autowired UsersServiceImpl usersService;
    public boolean LostpropertyInsert(String src, String userId, String name, String attribute, LocalDateTime time, String location, String type, String divid){
        Lostproperty lostproperty = new Lostproperty();
        lostproperty.setSrc(src);
        lostproperty.setTime(time);
        lostproperty.setLostPropertyName(name);
        lostproperty.setDescript(attribute);
        lostproperty.setLocation(location);
        lostproperty.setType(type);
        lostproperty.setDivid(divid);
        lostproperty.setCreatTime(time);
        lostproperty.setUserId(Integer.valueOf(userId));
        System.out.println("传进来的时间:"+time);
        if("寻物启事".equals(divid)) {
            lostproperty.setState("未找到");
        }
        if (lostpropertyMapper.insert(lostproperty)>0){
            return true;
        }
        return false;
    }
    public List<Lostproperty> queryLostForPage(String type,int page){
        IPage<Lostproperty> LostpropertyPage = new Page<>(page, 8);//参数一是当前页，参数二是每页个数
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("type",type);
        LostpropertyPage = lostpropertyMapper.selectPage(LostpropertyPage, queryWrapper);
        LostpropertyPage.getRecords().forEach(System.out::println);
        return LostpropertyPage.getRecords();
    }
    public int queryNum(String type){
        QueryWrapper qw=new QueryWrapper();
        qw.eq("type",type);
        List list = lostpropertyMapper.selectList(qw);
        return list.size();
    }
    public int delPropertyById(int id){
        int i = lostpropertyMapper.deleteById(id);
        return i;
    }

}
